document
		.write("<script src=\""
				+ context
				+ "/temp-store/jsstuff/tablequery/bestboy.js\" type=\"text/javascript\"></script>");

(function($) {

	$.grooveQuery = function(options) {
		var gridId = "" + options.queryKey, queryKey = options.queryKey, pageSize = options.pageSize, gridWidth = options.gridWidth, gridHeight = options.gridHeight, showIdx = options.showIdx;

		if (pageSize == null) {
			pageSzie = 30;
		}

		if (gridWidth == null) {
			gridWidth = '100%';
		}

		if (gridHeight == null) {
			gridHeight = '500';
		}

		if (tablequeryStuff[options.queryKey] == null) {
			alert("获取" + options.queryKey + "的命名空间失败");
		}

		/*
		 * var url = context +
		 * "/system/jquery.ligergrid.arg.do?method=modelcmp&querykey=" +
		 * queryKey;
		 */
		var url = context + "/temp-store/jsstuff/tablequery/"
				+ tablequeryStuff[options.queryKey] + "/" + options.queryKey
				+ ".json";

		/*
		 * if (options.params != null) { var str = json2param(options.params);
		 * if (str != "") { url += "&" + str; } }
		 */

		$.ajax({
			type : "POST",
			// contentType: "application/json",
			// //这段代码不要加，我时延的是否后台会接受不到数据
			url : url,
			dataType : "json",
			data : {
				queryKey : queryKey
			}, // 以json格式传递(struts2后台还是以string类型接受),year和month直接作为参数传递。
			success : function(modelcmpData) {
				if (!modelcmpData.success) {
					alert(modelcmpData.errorMsg);
					return false;
				}

				var columns = [];

				$.each(modelcmpData.resultData.columnModel, function(i, n) {
					if ((showIdx == null || showIdx == false)
							&& n.name == "PAGINATION_NUMBER") {
						// do nothing
					} else {
						var col = {
							display : n.display,
							name : n.name,
							align : n.align,
							hide : n.hide,
							width : parseInt(n.width),
							isSort : (n.alien != "1" && n.name != "PAGINATION_NUMBER"),
							isAllowHide : true
						}

						if (n.hide == false) {
							if (options.params != null
									&& options.params.comptype != null) {
								col.render = eval(options.params.comptype);
							} else {
								col.render = eval(n.render == ""
										? "defaultFnRender"
										: n.render);
							}
							// col.headerRender = eval(n.headerRender);
						}

						columns.push(col);
					}
				});

				$.each(modelcmpData.resultData.hiddenModel, function(i, n) {
							var col = {
								display : n.display,
								name : n.name,
								hide : true
							}

							columns.push(col);
						});

				var toolbar = null;

				if (modelcmpData.resultData.toolbars != null) {
					var toolbarItems = [];
					$.each(modelcmpData.resultData.toolbars, function(i, n) {
						toolbarItems.push({
							id : n.id,
							icon : n.iconcls,
							text : n.name,
							click : function(n) {
								var newDialog;

								var gv = new $.grooveView(n.id, {
									submitMessage : "确定提交保存",
									OKMessage : "保存成功",
									formID : n.id + "_form",
									mode : "insert",
									params : options.viewParams != null
											? options.viewParams
											: null,
									beforecall : function() {
										if ($("#" + n.id + "_target").length > 0) {
											$("#" + n.id + "_target").remove();
										}

										$("<div id=\"" + n.id
												+ "_target\"></div>")
												.append($("<form id=\"" + n.id
														+ "_form\"></form>"))
												.appendTo("body");
										$("#" + n.id + "_target").css(
												"display", "none");
									},
									aftercall : function() {
										newDialog.hide();

										grid.reload();
									},
									rendercall : function(selfFunc, validator,
											validators, viewConfig) {
										var viewSize = (new Function("return "
												+ viewConfig.size))();
										var winWidth = (viewSize != null
												&& viewSize.width != null
												? viewSize.width
												: 300);

										$("#" + n.id + "_form").css("width",
												winWidth * 0.95 + "px");

										newDialog = $.ligerDialog.open({
											title : viewConfig.name,
											target : $("#" + n.id + "_target"),
											width : winWidth,
											height : (viewSize != null
													&& viewSize.height != null
													? viewSize.height
													: 800),
											buttons : [{
												text : '确定',
												onclick : function(item, dialog) {
													$("#formID").handleSubmit(
															selfFunc,
															validator,
															validators,
															viewConfig);
												}
											}, {
												text : '取消',
												onclick : function(item, dialog) {
													dialog.hide();
												}
											}],
											isResize : true
										});

									}
								});
							}
						});

					});
				}

				mixToolbar(queryKey, toolbarItems);

				if (toolbarItems.length > 0) {
					toolbar = {
						items : toolbarItems
					};
				}

				var url = context
						+ "/system/jquery.ligergrid.arg.do?method=list&querykey="
						+ queryKey;

				if (options.params != null) {
					var str = json2param(options.params);
					if (str != "") {
						url += "&" + str;
					}
				}

				var grid = $("#" + gridId).ligerGrid({
							// title : modelcmpData.resultData.name,
							checkbox : modelcmpData.resultData.showchk,
							columns : columns,
							pageSize : pageSize,
							rownumbers : true,
							root : "rows",
							url : url,
							width : gridWidth,
							height : gridHeight,
							toolbar : toolbar

						});

				if (options.gridRender != null) {
					options.gridRender(grid);
				}
			}
		});

	};

	$.grooveComboboxQuery = function(options) {
		var gridId = "" + options.queryKey, queryKey = options.queryKey, pageSize = options.pageSize, gridWidth = options.gridWidth, gridHeight = options.gridHeight, showIdx = options.showIdx;

		if (pageSize == null) {
			pageSzie = 30;
		}

		if (gridWidth == null) {
			gridWidth = '100%';
		}

		if (gridHeight == null) {
			gridHeight = '100%';
		}

		if (tablequeryStuff[options.queryKey] == null) {
			alert("获取" + options.queryKey + "的命名空间失败");
		}

		/*
		 * var url = context +
		 * "/system/jquery.ligergrid.arg.do?method=modelcmp&querykey=" +
		 * queryKey;
		 */
		var url = context + "/temp-store/jsstuff/tablequery/"
				+ tablequeryStuff[options.queryKey] + "/" + options.queryKey
				+ ".json";

		var responseText = sendRequest(url);

		var modelcmpData = param2json(responseText);

		var columns = [];

		$.each(modelcmpData.resultData.columnModel, function(i, n) {
					if ((showIdx == null || showIdx == false)
							&& n.name == "PAGINATION_NUMBER") {
						// do nothing
					} else {
						var col = {
							display : n.display,
							name : n.name,
							align : n.align,
							hide : n.hide,
							width : parseInt(n.width),
							isSort : (n.alien != "1" && n.name != "PAGINATION_NUMBER"),
							isAllowHide : true
						}

						if (options.params != null
								&& options.params.comptype != null) {
							col.render = eval(options.params.comptype);
						} else {
							col.render = eval(n.render == ""
									? "defaultFnRender"
									: n.render);
						}

						columns.push(col);
					}
				});

		var fields = [];

		$.each(modelcmpData.resultData.queryModel, function(i, n) {
					fields.push({
								name : n.name,
								label : n.display,
								width : 90
							});
				});

		var queryurl = context
				+ "/system/jquery.ligergrid.arg.do?method=list&querykey="
				+ queryKey;

		if (options.params != null) {
			var str = json2param(options.params);
			if (queryurl != "") {
				queryurl += "&" + str;
			}
		}

		var gridOptions = {
			title : modelcmpData.resultData.name,
			checkbox : modelcmpData.resultData.showchk,
			columns : columns,
			pageSize : pageSize,
			rownumbers : true,
			root : "rows",
			url : queryurl,
			width : gridWidth,
			height : gridHeight,
			conditions : {
				fields : null
			}
		};

		return gridOptions;

	};
})(jQuery);

function mixToolbar(items) {

}

function defaultFnRender(rowdata, rowindex, value, column) {
	return value;
}

// column display isnot null && "",call defaultHeaderFnRender
function defaultHeaderFnRender(column) {
}